package com.example.response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.example.network.Response;
import com.example.resource.City;
import com.example.resource.Province;

public class CityResponse extends Response {

	public List<Province> provinceList;

	public List<City> cityList;

	public Map<Integer, List<City>> cityListMap;

	@Override
	protected void jsonToObject() {
		provinceList = new ArrayList<Province>();
		cityListMap = new HashMap<Integer, List<City>>();
		try {
			JSONObject data = reposonJson.getJSONObject("result");
			JSONArray array = data.getJSONArray("data");
			int size = array.length();
			for (int i = 0; i < size; i++) {
				JSONObject object = array.getJSONObject(i);
				Province province = new Province();
				province.provinceName = object.optString("provinceName");
				provinceList.add(province);
				JSONArray array2 = object.getJSONArray("cityList");
				int size2 = array2.length();
				Log.e("result", "@@@" + size2);
				cityList = new ArrayList<City>();
				for (int j = 0; j < size2; j++) {
					JSONObject object2 = array2.getJSONObject(j);
					City city = new City();
					city.cityName = object2.optString("cityName");
					city.branchDistrictNo = object2.optString("branchDistrictNo");
					cityList.add(city);
				}
				cityListMap.put(i, cityList);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

}